package network;

import java.io.IOException;
import java.net.DatagramPacket;
import java.net.DatagramSocket;
import java.net.SocketException;

/**
 * <p>
 *
 * </p>
 *
 * @author LovelyBigDuck
 * @date 2021/5/24 21:58
 */
public class UdpServer {
    public static void main(String[] args) throws IOException {
        int port=8888;
        byte[] data = new byte[1024];
        DatagramSocket socket = new DatagramSocket(port);

        DatagramPacket datagramPacket = new DatagramPacket(data, data.length);
        socket.receive(datagramPacket);
        String s = new String(datagramPacket.getData(), 0, datagramPacket.getLength());
        System.out.println("收到消息:"+s);
    }
}
